var app = getApp(),
a = app.requirejs('core');

Page({
    data: {
      show:false,
        total_price: 0,
        price: 0,
        cash_price: 0,
        total_cash: 0,
        team_count: 0,
        order_money: 0,
        display: false
    },

  onGotUserInfo: function (q) {
    var that = this,
        cache = app.getCache("userinfo");

    // if (cache) {
    //     return;
    // }
    app.getUserInfo(q.detail.userInfo, function (t) {
      if (t != 1000) {
        var ucache = getApp().getCache("userinfo");
        if (ucache) {
          //var options = that.data.options;
          //that.getDetail(options)
          //getCurrentPages()[getCurrentPages().length - 1].onLoad();
          that.setData({
            display: false,
            //getPhoneAuth: getApp().globalData.getphone
          })
        }
      } else {
        that.setData({
          display: true
        })
      }

    }, q.detail.encryptedData, q.detail.iv);
  },

  // 授权获取用户信息判断
  authCheck: function () {
    var cache = getApp().getCache("userinfo");
    if (!cache.nickName && !cache.avatarUrl) {
      this.setData({
        display: true
      })
      return false;
    } else {
      this.setData({
        display: false
      })
      return true;
    }
  },

  // 取消登录
  cancel_auth: function () {
    this.setData({
      display: false
    })
  },

  onLoad: function (e) {
    a.ReName(e.title);
    var that = this;

    var cache = getApp().getCache("userinfo");
    if (!cache.nickName && !cache.avatarUrl) {
      getApp().authSwitch(function(res){
        if (res == 1) {
          that.setData({
            display: true
          })
        } else {
          if (cache) {
            that.setData({
              display: false
            })
          } else {
            that.setData({
              display: true
            })
          }
        }
      })
    }

    that.getInfo()
  },
  getInfo: function () {
    var that = this;
    var user_id = app.getCache('userinfo').uid != undefined ? app.getCache('userinfo').uid : 0
    a.get('Distribe/shareSetting',{},function(t){
      console.log("sa",t);
      if(t.code==0){
        app.setCache('shareSetting',t.info);
        that.setData({
          shareSetting:t.info
        })
      }
    })
    a.get('Distribe/userinfo', { uid: user_id }, function (t) {
      console.log("sb",t);
      if (t.code == 0) {
        app.setCache('share_userinfo', t.info);
        that.setData({
          user_info: t.info,
          show: true
        })
      } else {
        a.alert(t.msg, function () {
          a.jump('', 5)
        })
      }
    }, true)
  },

    onReady: function() {},
    onShow: function() {
        
    },

  // 提现
    gocash: function() {
      var auth_res = this.authCheck();
      if (!auth_res) {
        return;
      }

      a.jump('/yb_mingpian/pages/fenxiao/pages/cash/cash');
    },
// 查看总分销佣金
  viewcash: function() {
    var auth_res = this.authCheck();
    if (!auth_res) {
      return;
    }

    a.jump('/yb_mingpian/pages/fenxiao/pages/share-money/share-money?title='+this.data.shareSetting.other[5]);
  },

  // 推广二维码
  share_qrcode: function() {
    var auth_res = this.authCheck();
    if (!auth_res) {
      return;
    }

    a.jump('/yb_mingpian/pages/fenxiao/pages/share-qrcode/share-qrcode?title='+this.data.shareSetting.other[9]);
  },

    onPullDownRefresh: function() {
      var that = this;
      that.getInfo();
      wx.stopPullDownRefresh();
    },
    onReachBottom: function() {},

    apply: function(e) {
      var auth_res = this.authCheck();
      if (!auth_res) {
        return;
      }

      var that=this;
      a.jump('../add-share/index?title=申请'+that.data.shareSetting.other[13])
    },
    home:function(e){
      //a.jump('/yb_mingpian/pages/shop/index',4)
      a.jump('/yb_mingpian/pages/cardinfo/index',4)
    }
});